﻿#ifndef ACCOUNT_DB_H
#define ACCOUNT_DB_H

#include <QSqlDatabase>
#include <QSqlQuery>
#include <QString>
#include <QDebug>
#include <QFile>
#include <QTextStream>
#include <QTime>
#include <QDate>
#include <QList>

#include "database.h"

class DATABASE_EXPORT account_db: public Database
{
public:
    account_db(QString db_name);

    QStringList account_find_groups();
    bool check_table(QString table_name);
    bool insert_check( QString table ,
                                QString check_row,QString check_data);
    char insert_group_data(QString Data);
    char delate_group_data(QString Data);
    void insert_person_data(QString Data);
    void delate_person_data(QString Data);
    char insert_relation_data( QString person,
                                       QString amount,
                                       QString group,
                                       QString date,
                                       QString remark);
    char delete_relation_data_accurate(QString person,
                                       QString amount,
                                       QString group,
                                       QString date,
                                       QString remark);
    float count_table_data(QString table);
    void delete_relation_data_match(QString row_name, QString match_str);
    QList<float> count_amount_all();
    QList<float> count_amount_group( QString group_name);
    QList<QString> select_relation_items( QList<QString> row_name, QList<QString> condition);
    float count_amount_date(QString date_begin, QString date_end);

    QString ACCOUNT_DB_PATH = "data/account/";
    QSqlDatabase account_data_db;
private:
    QSqlDatabase m_db;
    //数据库创建表的基本执行语句
    //用户信息表
    QString CREATE_USER = "create table user_info (id int primary key, name varchar(20),password VARCHAR(8))";

    //数据表
    QString CREATE_PERSON = "create table person(id int primary key, name varchar(20) unique, remark varchar(50))";
    QString CREATE_GROUP = "create table m_group(id int primary key, group_name varchar(20) unique, remark varchar(50))";
    QString CREATE_RELATION = "create table relation(id int primary key, personName varchar(20), amount varchar(10), time date, "
                             "groupName varchar(20), remark varchar(50),"
                             "CONSTRAINT fk_person FOREIGN KEY(personName ) REFERENCES person(name ),"
                             "CONSTRAINT fk_group FOREIGN KEY(groupName ) REFERENCES m_group(group_name ))";
    //查找命令
    QString SELECT_PERSON = "select name from person";
    QString SELECT_GROUP = "select group_name from m_group";
};

#endif // ACCOUNT_DB_H
